package com.salinity.kun.task;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.swing.plaf.synth.SynthSpinnerUI;

import com.salinity.kun.helper.BaseHydrologyDataHelper;
import com.salinity.kun.helper.CalculationHelper;
import com.salinity.kun.helper.OracleHelper;
import com.salinity.kun.model.StationDateData;
import com.salinity.kun.util.PathUtil;

public class DatongLLTask implements ITask {

	public List<StationDateData> getFluxDataFromDB(Date sDate, Date eDate, int interval)
			throws IOException, ParseException {
		OracleHelper oracleHelper = new OracleHelper();
		List<StationDateData> fluxList = null;
		ResultSet rsltSet;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
		try {
			oracleHelper.prepareFluxSQL();
			rsltSet = oracleHelper.doFluxQuery(sDate, eDate);

			fluxList = oracleHelper.parseRslt(rsltSet, sdf);

			oracleHelper.end();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return fluxList;
	}

	@Override
	public boolean run() throws IOException, ParseException {


		int interval = 5;
		Path inputPath = Paths.get("E:\\Kuner\\BYLW\\Jworkspace\\saltyCode\\testify\\data\\dtq2005.csv");
		// 存到本地文件
		Path outputPath = Paths.get("E:\\Kuner\\BYLW\\Jworkspace\\saltyCode\\testify\\data\\avg_flux_2005_" + interval + ".csv");
		PathUtil.preparePath(outputPath);
		
		List<StationDateData> fluxList = BaseHydrologyDataHelper.getStationDateDataFromFile(inputPath,1,0,2);
		List<StationDateData> avgList = BaseHydrologyDataHelper.fluxFilter(fluxList, interval);
		BaseHydrologyDataHelper.writeToFile(avgList, outputPath);
		return false;
	}

	public static void main(String[] args) {
		ITask itask = new DatongLLTask();
		try {
			itask.run();

		} catch (IOException | ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
